
class GameEvent:
    def __init__(self, type):
        self.type = type
        self.data = {}

class GameEventManager:
    events = []
    event_handlers = dict()

    @classmethod
    def dispatch_event(cls):
        while len(cls.events) > 0:
            e = cls.events.pop(0)
            handlers = cls.event_handlers.get(e.type)
            if handlers:
                for handler in handlers:
                    handler(e)

    @classmethod
    def register_handler(cls, type, handler):
        if type in cls.event_handlers:
            cls.event_handlers.get(type).append(handler)
        else:
            cls.event_handlers[type] = []
            cls.event_handlers[type].append(handler)

    @classmethod
    def remove_handler(cls, type, handler):
        pass    # todo

    @classmethod
    def post_event(cls, event):
        cls.events.append(event)
